# -*- coding: utf-8 -*-
# @Time    : 2023/6/2 19:27
# @Author  : Pan
# @Software: PyCharm
# @Project : VisualFramework
# @FileName: ResNet50.py

image_size = (224, 224)
max_steps = 20000

config = {
    "type": "Clas",
    "base_info": {
        "step": max_steps,
        "dot": 20,
        "save_iters": 200,
        "pretrained": None,
        "save_path": "output/",
        "log_dir": "log_dir/",
    },
    "train_dataset": {
        "type": "ClasBaseDataset",
        "batch_size": 256,
        "shuffle": True,
        "num_workers": 2,
        "data_root": "data",
        "data_list": "data/train.txt",
        "transforms": [
            {
                "type": "LoadData",
                "keys": ["img"],
                "func": "cv2"
            },
            {
                "type": "ResizeByShort",
                "keys": ["img"],
                "short": [i for i in range(128, 512, 1)],
                "inter": ["bilinear"]
            },
            {
                "type": "RandPaddingCrop",
                "keys": ["img"],
                "pad_size": image_size,
                "crop_size": image_size
            },
            {
                "type": "ToTensor",
                "keys": ["img"]
            },
            {
                "type": "Normalize",
                "keys": ["img"],
                "mean": 0.5,
                "std": 0.5
            }
        ]
    },
    "val_dataset": {
        "type": "ClasBaseDataset",
        "batch_size": 256,
        "shuffle": True,
        "num_workers": 2,
        "data_root": "data",
        "data_list": "data/val.txt",
        "transforms": [
            {
                "type": "LoadData",
                "keys": ["img"],
                "func": "cv2"
            },
            {
                "type": "ResizeByShort",
                "keys": ["img"],
                "short": [224],
                "inter": ["bilinear"]
            },
            {
                "type": "RandPaddingCrop",
                "keys": ["img"],
                "pad_size": image_size,
                "crop_size": image_size
            },
            {
                "type": "ToTensor",
                "keys": ["img"]
            },
            {
                "type": "Normalize",
                "keys": ["img"],
                "mean": 0.5,
                "std": 0.5
            }
        ]
    },
    "optimizer": {
        "type": "adam",
        "lr_scheduler": {
            "type": "WarmupCosineLR",    # Warm up 学习率刚开始是由小变大，Cosine
            "learning_rate": 0.001,
            "total_steps": max_steps,
            "warmup_steps": 500,
            "warmup_start_lr": 1e-7,
            "end_lr": 1e-7
        },
        "decay": None
    },
    "network": {
        "type": "clas",
        "network": {
            "type": "ResNet",
            "structure": 50,
            "num_classes": 257
        }
    },
    "loss": {
        "loss_list": [
            {
                "type": "CrossEntropyLoss"
            }
        ],
        "loss_coef": [1]
    },
    "metric": [
        {
            "type": "ACC",
            "topk": (1, 5)
        }
    ],
    "amp": {
        "scale": 1024
    }
}
